﻿using UnityEngine;
using System.Collections;

public class RotateAround : MonoBehaviour {

	public float rotateSpeed = 1f;
	public  Transform[] rotaObject;

	void Update(){
		if (!isDraging) {
			for (int i = 0; i < rotaObject.Length; i++) {
				Quaternion q = Quaternion.LookRotation (new Vector3(0,6,-1));
				rotaObject[i].localRotation = Quaternion.Slerp (rotaObject[i].localRotation, q, Time.deltaTime*5);
			}
		}
	}
	bool isDraging;
	public void OnDragStart(){
		isDraging = true;
	}
	public void OnDrag(Vector2 delta){
		for (int i = 0; i < rotaObject.Length; i++) {
			rotaObject [i].RotateAround (rotaObject [i].position, rotaObject [i].forward, -0.5f * delta.x * rotateSpeed);
		}
	}
	public void OnDragEnd(){
		isDraging = false;
	}
}